package com.qd.push.mq.httpmsg;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

/**
 * @author sjk
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class HkMsgProducer {
    private final StreamBridge streamBridgeTemplate;

    public void sender(String playLoad, Integer delayTime) {
        Message<String> message = MessageBuilder.withPayload(playLoad).setHeader("x-delay", delayTime * 1000).build();
        boolean send = streamBridgeTemplate.send("sendHttp-out-0", message);
        log.info("进入延时队列，内容： {},状态: {},delayTime: {}", playLoad, send, delayTime);
    }

    public boolean sender(String playLoad) {
        log.info("进入消息队列，内容： {}", playLoad);
        Message<String> message = MessageBuilder.withPayload(playLoad).build();
        return streamBridgeTemplate.send("sendHttp-out-0", message);
    }
}
